﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BestLifePOS_Core.Data.Core;
using BestLifePOS_Core.DomainObjects;
using System.Data.SqlClient;
using System.Data;
using BestLifePOS_Core.Exceptions.DataBase;

namespace BestLifePOS_Core.Data.Commands
{

    class BestlifeGetStkByBranchId : BestLifeDataAction<DataTable>
    {
         private string GvBrnhId;
         DataTable GvTable = new DataTable();
         public BestlifeGetStkByBranchId(string PBrnhId)
        {
            GvBrnhId = PBrnhId;
        }


         public override DataTable Body(SqlConnection PConn)
         {
             try
             {

                 #region Datatable

                 GvTable.Columns.Add("Stock_Id");
                 GvTable.Columns.Add("Pro_Name");
                 GvTable.Columns.Add("Category");
                 GvTable.Columns.Add("Qty");              
                 GvTable.Columns.Add("Reorder_Qty");
                 GvTable.Columns.Add("Reorder_Level");
      


                 #endregion

                 List<string> LvList = new List<string>();


                 SqlCommand LvCommand = new SqlCommand();
                 LvCommand.Connection = PConn;
                 LvCommand.CommandType = CommandType.StoredProcedure;
                 LvCommand.Parameters.Add(new SqlParameter("@Branch_Id", GvBrnhId));//when passing parameters to the SP
                 LvCommand.CommandText = "dbo.GetStockByBranchId";
                
              

                 SqlDataReader LvReader = LvCommand.ExecuteReader();
                 while (LvReader.Read())
                 {
                     GvTable.Rows.Add(GvTable.NewRow());
                 //    string GVTest;

                     GvTable.Rows[GvTable.Rows.Count - 1][0] = LvReader.GetValue(0).ToString();
                     GvTable.Rows[GvTable.Rows.Count - 1][1] = LvReader.GetValue(1).ToString();
                     GvTable.Rows[GvTable.Rows.Count - 1][2] = LvReader.GetValue(2).ToString();
                     GvTable.Rows[GvTable.Rows.Count - 1][3] = LvReader.GetValue(3).ToString();
                     GvTable.Rows[GvTable.Rows.Count - 1][4] = LvReader.GetValue(4).ToString();
                     GvTable.Rows[GvTable.Rows.Count - 1][5] = LvReader.GetValue(5).ToString();

                 //    GVTest.
                     //GvTable.Rows[GvTable.Rows.Count - 1][7] = "0";



                 }
                 return GvTable;
             }
             catch (BestlifeDatabaseException e)
             {
                 throw new BestlifeDatabaseException(e);
             }
         }

    
    }


}
